import { storageLocal } from "@pureadmin/utils";

const LOCAL_NAME = "KBStorage";

interface Props {
  code: string;
  dataType: string;
  name: string;
}

interface Tag {
  backgroundColor: string;
  code: string;
  defaultName: string | null;
  defaultNameCode: string;
  displayX: string | number;
  displayY: string | number;
  icon: string;
  id: string;
  name: string;
  objType: number | string;
  propertyDTOList: Props[];
}

interface TagEdge {
  code: string;
  id: string;
  defaultName: string | null;
  defaultNameCode: string;
  backgroundColor: string;
  dstId: string;
  srcId: string;
  name: string;
  propertyDTOList: Props[];
}

export interface KBState {
  tags: Tag[];
  tagEdges: TagEdge[];
}

export function defaultSetting(): KBState {
  return {
    tags: [],
    tagEdges: [],
  };
}

export function getLocalState(): KBState {
  const localSetting: KBState | undefined =
    storageLocal().getItem<KBState>(LOCAL_NAME);
  return { ...defaultSetting(), ...localSetting };
}

export function setLocalState(drawer: KBState): void {
  storageLocal().setItem(LOCAL_NAME, drawer);
}

export function removeLocalState() {
  storageLocal().removeItem(LOCAL_NAME);
}
